 

package com.zdkj.subway.rca.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.zdkj.common.core.util.R;
import com.zdkj.common.log.annotation.SysLog;
import com.zdkj.common.security.util.ObjectUtils;
import com.zdkj.subway.rca.dto.in.SwCkConfiirmProcessQrcodeEpaymentDTO;
import com.zdkj.subway.rca.entity.SwCkConfiirmProcessQrcodeEpayment;
import com.zdkj.subway.rca.service.SwCkConfiirmProcessQrcodeEpaymentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;


/**
 * 对账确认过程-二维码电子支付表
 *
 * @author stw
 * @date 2020-10-26 15:13:15
 */
@RestController
@AllArgsConstructor
@RequestMapping("/swckconfiirmprocessqrcodeepayment" )
@Api(value = "swckconfiirmprocessqrcodeepayment", tags = "银行票据单管理-银行电子账单与对账确认表-对账确认过程-二维码电子支付表管理")
public class SwCkConfiirmProcessQrcodeEpaymentController {

    private final SwCkConfiirmProcessQrcodeEpaymentService swCkConfiirmProcessQrcodeEpaymentService;

    /**
     * 列表查询
     * @param
     * @return
     */
    @ApiOperation(value = "列表查询", notes = "列表查询")
    @GetMapping("/listSwCkConfiirmProcessQrcodeEpayment" )
    public R listSwCkConfiirmProcessQrcodeEpayment(String startDate,String endDate,String confirmStatus) {
        String ordflag = null;
        return R.ok(swCkConfiirmProcessQrcodeEpaymentService.listSwCkConfiirmProcessQrcodeEpayment(startDate,endDate,confirmStatus,ordflag));
    }

    /**
     * 二维码支付批量确认，注意：只填充状态是未确认的
     * @param list
     * @return
     * @throws Exception
     */
    @ApiOperation(value = "二维码支付批量确认，注意：只填充状态是未确认的", notes = "二维码支付批量确认，注意：只填充状态是未确认的")
    @SysLog("二维码支付批量确认")
    @PostMapping({ "/saveBatchConfirm" })
    @PreAuthorize("@pms.hasPermission('sw_ck_confiirm_process_qrcode_epayment_confirm')")
    public R saveBatchConfirm(@RequestBody  List<SwCkConfiirmProcessQrcodeEpaymentDTO> list) throws Exception {

        List<SwCkConfiirmProcessQrcodeEpayment> listDb = new ArrayList<>();
        for(SwCkConfiirmProcessQrcodeEpaymentDTO swCkConfiirmProcessQrcodeEpayment : list){
            final SwCkConfiirmProcessQrcodeEpayment obj =  ObjectUtils.getDefaultObj(SwCkConfiirmProcessQrcodeEpayment.class);
            BeanUtils.copyProperties(swCkConfiirmProcessQrcodeEpayment,obj);
            listDb.add(obj);
        }

        return R.ok(swCkConfiirmProcessQrcodeEpaymentService.saveBatch(listDb));
    }
    /**
     * 二维码支付批量删除确认，注意：只填充状态是已确认的
     * @param list
     * @return
     * @throws Exception
     */
    @ApiOperation(value = "二维码支付批量删除确认，注意：只填充状态是已确认的", notes = "二维码支付批量删除确认，注意：只填充状态是已确认的")
    @SysLog("二维码支付批量删除确认")
    @PostMapping({ "/delBatchConfirm" })
    public R delBatchConfirm(@RequestBody  List<SwCkConfiirmProcessQrcodeEpaymentDTO> list) throws Exception {

        for(SwCkConfiirmProcessQrcodeEpaymentDTO swCkConfiirmProcessQrcodeEpayment : list){
            LambdaQueryWrapper<SwCkConfiirmProcessQrcodeEpayment> queryWrapper = Wrappers.<SwCkConfiirmProcessQrcodeEpayment>lambdaQuery()
                    .eq(SwCkConfiirmProcessQrcodeEpayment::getTradeDate, swCkConfiirmProcessQrcodeEpayment.getTradeDate());
            swCkConfiirmProcessQrcodeEpaymentService.remove(queryWrapper);
        }

        return R.ok();
    }
    /**
     * 导出
     * @param
     * @return
     * @throws IOException
     */
    @ApiOperation(value = "二维码支付导出", notes = "二维码支付导出")
    @GetMapping({"/export"})
    @SysLog("二维码支付导出")
    @PreAuthorize("@pms.hasPermission('sw_ck_confiirm_process_qrcode_epayment_export')")
    public void export(String startDate,String endDate,String confirmStatus,HttpServletResponse response){
        String ordflag = "1";
        swCkConfiirmProcessQrcodeEpaymentService.exportExcel(startDate,endDate,confirmStatus,ordflag,response);
    }

}
